function hiddenPop()
{
  $(".pop").hide();	
}
function getMemberLevel() {
  function doCallBack(res) {
    if (res.retcode == 0) {
      console.log(res)
      let result = JSON.parse(Base64.decode(res.data));
      console.log(result);
      // 如果会员等级=0，显示“填写邀请码”，点击弹出输入邀请码对话框，提交调用接口：account.writeinvitecode
      // 如果会员等级=1，显示“提升会员等级”，点击弹出填写姓名和手机号的页面，如果已经填写则调接口：account.getapplyup 填充内容，提交接口：account.applymemberup
      // 如果会员等级=2，两个按钮都不显示
      // memberLevel的值为用户等级 0普通会员 1优选会员 2共生会员
      if (result) {
        if (result.member_level.memberlevel == 0) {
          $(".hrefContainer .fillIn").css({
            "display": "flex"
          });
        } else if (result.member_level.memberlevel == 1) {
          $(".hrefContainer .elevate").css({
            "display": "flex"
          });
        }
      }
    }

  }

  jAjax("account.getmemberlevel", doCallBack, {});
}
getMemberLevel();

$('.cancel').click(function () {
  $(".pop").hide();
})
$(".fillIn").click(function () {
  $(".pop,.shadow,.fillCon").show();
})

$("#submitInviteCode").click(function () {
  var inviteCode = $('#inviteCode').val();
  if (inviteCode != "") {
    var sval = {
      code: inviteCode
    };

    function doCallBack(res) {
      console.log(res);
      if (res.retcode == 0) {
        DoAlert('提交成功',hiddenPop);
      } else {
        DoAlert(res.message);
      }
    }
    jAjax("account.writeinvitecode", doCallBack, sval);
  } else {
    DoAlert('请输入正确的邀请码');

  }
})

$(".elevate").click(function () {
  $(".pop,.shadow,.upInvite").show();
  getUpInfo();
})

function getUpInfo() {
  function doCallBack(res) {
    console.log(res);
    if (res.retcode == 0) {
		let result = JSON.parse(Base64.decode(res.data));
		
      $('#name').val(result.contact_name);
      $('#telphone').val(result.contact_telephone);
	  if(result.is_do == 0)
	  {
		  $(".upInvite .buttonCon").css({
			"display": "flex"
		  });
	  }
    } else {
      $(".upInvite .buttonCon").css({
        "display": "flex"
      });
    }
  }
  jAjax("account.getapplyup", doCallBack, {});
}
$("#submitUp").click(function () {
  var name = $('#name').val();
  var telphone = $('#telphone').val();
  if (name == "") {
    DoAlert('请输入正确的姓名');

  } else if (telphone == "" || !(/^1\d{10}$/.test(telphone))) {
    DoAlert('请输入正确的手机号码');
  } else {
    var sval = {
      contact_name: name,
      telephone: telphone
    }

    function doCallBack(res) {
      console.log(res);
      if (res.retcode == 0) {
        DoAlert('提交成功',hiddenPop);
      } else {
        DoAlert(res.message);
      }
    }
    jAjax("account.applymemberup", doCallBack, sval);
  }
})